package com.exercise.widgets.spinner

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatSpinner
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.ViewModel
import com.exercise.struct.base.BaseActivity
import com.exercise.struct.viewmodel.BaseViewModel
import com.exercise.widgets.R
import com.exercise.widgets.databinding.ActivitySpinnerBinding

class SpinnerActivity : BaseActivity<BaseViewModel, ActivitySpinnerBinding>() {
    override val bindingInflater: (LayoutInflater) -> ActivitySpinnerBinding
        get() = ActivitySpinnerBinding::inflate
    override val modelClass: Class<BaseViewModel>
        get() = BaseViewModel::class.java

    override fun initView() {
        val adapter1 = ArrayAdapter.createFromResource(
            this,
            R.array.arrayData,
            android.R.layout.simple_spinner_item
        ).apply {
            setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        }
        binding.spinner1.adapter = adapter1


        val data = resources.getStringArray(R.array.arrayData).toMutableList()
        binding.spinner2.adapter = MySpinnerAdapter<String>(data)
        binding.spinner2.onItemSelectedListener = object :OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {

                Log.d("SpinnerActivity","onItemSelected: $position")
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {
                Log.d("SpinnerActivity","onNothingSelected: ")
            }
        }

    }

    override fun initData() {
    }

    companion object {
        fun start(context: Context) {
            Intent(context, SpinnerActivity::class.java).also {
                context.startActivity(it)
            }
        }
    }

}